//
//  AccountSecurityViewController.m
//  PigMarket
//
//  Created by mac on 2019/3/20.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AccountSecurityViewController.h"
#import "SystemSetingCell.h"
#import "RealNameViewController.h"
#import "AccountBoundViewController.h"
#import "PayPasswordViewController.h"
#import "ModifyUserInfoViewController.h"
#import "ModifyPassWordViewController.h"



@interface AccountSecurityViewController ()

/**
 dataArr
 */
@property (nonatomic , strong) NSArray *dataArr;

@property (nonatomic, assign) BOOL isHavePayword; //是否有支付密码

@end

@implementation AccountSecurityViewController

#pragma mark - view life cycle

- (void)setupUI{

    self.baseNavView.navTitleLabel.text = @"账号与安全";
    self.tableView.separatorColor = mIconLineColor;
    self.tableView.rowHeight = 54.f;
}

- (void)setupLayout{
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(TJ_NavBarHeight);
        make.right.left.bottom.mas_equalTo(self.view);
    }];
}


- (void)initData {
    
    UserInfo *userInfo = [UserInfoDataProvider sharedInstance].userInfo;
    NSString *aims = userInfo.memberName && userInfo.memberName.length >0 ?@"已认证" :@"未认证";
    
    self.dataArr = @[@[@{@"title":@"账号绑定",@"detail":@""}],
                     @[@{@"title":@"实名认证",@"detail":aims},
                       @{@"title":@"支付密码",@"detail":@""},
                       @{@"title":@"修改密码",@"detail":@""}]];
}

#pragma mark - delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArr.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.dataArr[section] count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SystemSetingCell *cell = [SystemSetingCell cellWithTableView:tableView];
    cell.infoDic = self.dataArr[indexPath.section][indexPath.row];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        [self.navigationController pushViewController:[[AccountBoundViewController alloc] init] animated:YES];
        
    }else if (indexPath.section == 1){
        switch (indexPath.row) {
            case 0://实名认证
            {
                RealNameViewController *realNameVC = [[RealNameViewController alloc] init];
                [self.navigationController pushViewController:realNameVC animated:YES];
                
            }
                break;
            case 1://支付密码
            {
                self.isHavePayword = YES;
                PayPasswordViewController *payPasswordVC = [[PayPasswordViewController alloc] init];
                payPasswordVC.type = self.isHavePayword ?PayPasswordViewControllerType_OriginPay :PayPasswordViewControllerType_SetUp;
                [self.navigationController pushViewController:payPasswordVC animated:YES];
            }
                break;
            case 2://修改密码
            {
//                ModifyUserInfoViewController *modifyUserInfoViewController = [[ModifyUserInfoViewController alloc] init];
//                modifyUserInfoViewController.title = @"修改密码";
//                modifyUserInfoViewController.modifyUserInfoType = ModifyUserInfoTypePassword;
//                //modifyUserInfoViewController.userInfoModel = self.userInfoModel;
//                [self.navigationController pushViewController:modifyUserInfoViewController animated:YES];
                
                ModifyPassWordViewController *vc = [[ModifyPassWordViewController alloc] init];
                [self.navigationController pushViewController:vc animated:YES];
                
            }
                break;
            default:
                break;
        }
    }
}


#pragma mark - private method
//- (void)writeOffRequest {
//    NSNumber *memberId = [UserInfoDataProvider sharedInstance].userInfo.memberId;
//    [[[PigMarketApi sharedInstance] userAccountWriteOffWithMemberId:memberId] subscribeNext:^(NSNull * _Nullable x) {
//
//    } error:^(NSError * _Nullable error) {
//
//    }];
//}


#pragma mark - getter and setter

- (NSArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [[NSArray alloc] init];
    }
    return _dataArr;
}

- (void)registerTableViewCell{
    
    self.tableView.mj_footer.hidden = YES;
    self.tableView.mj_header.hidden = YES;
}


@end

